cmake_minimum_required(VERSION 3.1)
project(httpserver C)
find_package ( Threads REQUIRED )
SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
macro(use_c99)
    if (CMAKE_VERSION VERSION_LESS "3.1")
        if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
            set(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
        endif ()
    else()
        set(CMAKE_C_STANDARD 99)
    endif ()
endmacro(use_c99)

set(CMAKE_C_STANDARD 99)
set(project_name, httpserver)
include_directories("src/core")
include_directories("src/hash")
include_directories("src/net")
include_directories("src/net/io")
include_directories("src/net/http")
include_directories("src/net/http/application")
include_directories("src/utils")

IF (WIN32)
    link_libraries(ws2_32 wsock32)
ENDIF ()

set(core
        src/core/conf.c
        src/core/unix/http_log.c
        src/core/unix/http_thread.c
        src/core/unix/http_code.c
        src/core/unix/http_signal.c
        src/core/unix/http_times.c
        src/core/unix/http_string.c
        src/core/unix/http_file.c
        src/core/unix/http_alloc.c
        src/core/unix/http_tmalloc.c)
set(utils
        src/utils/json.c
        src/utils/lstring.c)
set(hash
        src/hash/lock.c
        src/hash/container.c
        src/hash/dts.c
        src/hash/hash.c
        src/hash/md5.c
        src/hash/sha.c
        src/hash/tree.c
        src/hash/hash_util.c)

set(net
        src/net/http_io.c
        src/net/http_tcp.c
        src/net/http_socket.c
        src/net/http_connect.c
        src/net/io/http_epoll.c
        src/net/io/http_poll.c
        src/net/io/http_select.c
        src/net/io/http_pipe.c
        src/net/io/http_multi_io.c
        src/net/http/http_handler.c
        src/net/http/http_request.c
        src/net/http/http_response.c
        src/net/http/http_req_header.c
        src/net/http/http_rep_header.c
        src/net/http/http_req_rep_com.c
        src/net/http/application/file_system.c
        src/net/http/application/port_system.c)
set(main
        httpserver.c
        ${core}
        ${utils}
        ${hash}
        ${net})


set(conf_config ${CMAKE_BINARY_DIR}/conf)
set(html_config ${CMAKE_BINARY_DIR}/html)
# 创建 html 指向的文件夹
execute_process( COMMAND ${CMAKE_COMMAND} -E make_directory ${conf_config})
execute_process( COMMAND ${CMAKE_COMMAND} -E make_directory ${html_config})
# 拷贝 html中文件夹下的内容  到  html_conf_dir 中
execute_process( COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/conf ${conf_config})
execute_process( COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/html ${html_config})


add_executable(${PROJECT_NAME} ${main}  test/server.c test.c)
#add_executable(${PROJECT_NAME} test/server.c test.c)
target_link_libraries(${PROJECT_NAME} -lpthread)
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT})
use_c99()